package mathgame.core;

import java.util.*;
import mathgame.filehandler.IFileHandler;
import mathgame.filehandlerimpl.ImplFileHandler;

public class Highscore extends Observable {

    private IFileHandler hs;
    private Map<Integer, String> tmpMap, sortedMap;

    private static Highscore highscore = null;
    protected Highscore() {
        hs = new ImplFileHandler();

    }
    public static Highscore getHighscore() {
        if(highscore == null) {
            highscore = new Highscore();
        }
        return highscore;
    }
    
    public void initiateHighscore(){
        try {
            tmpMap = hs.readFile();
              sortedMap = new TreeMap<Integer, String>(tmpMap);
        setChanged();
        notifyObservers(sortedMap);
        } catch (Exception e) {
            setChanged();
            notifyObservers(null);
            e.printStackTrace();
        }

    }

    public void addToHighscore(String name, Integer score){
    		hs.saveFile(name + "-" + score);
    }
}


